using System.IO;
using System.Text;

namespace Engine.FileFormats3D.WR2TrafficFiles
{
    public class SplineData
    {
        #region Private Fields

        private long baseStreamPosition;
        private int id;
        private byte index3;
        private byte index4;
        private byte index5;
        private byte index6;

        //byte index1;
        //byte index2;
        private short value;

        #endregion Private Fields

        #region Public Constructors

        public SplineData(int index, byte value1, byte value2, byte value3, byte value4)
        {
            this.id = index;
            baseStreamPosition = 0;// br.BaseStream.Position;

            this.value = (short)index;
            this.index3 = value1;
            this.index4 = value2;
            this.index5 = value3;
            this.index6 = value4;
            //this.index3 = 0xFF;
            //this.index4 = 0xFF;
            //this.index5 = 0xFF;
            //this.index6 = 0xFF;
        }

        public SplineData(BinaryReader br, int index)
        {
            this.id = index;
            baseStreamPosition = br.BaseStream.Position;

            this.value = br.ReadInt16();
            //this.index1 = br.ReadByte();
            //this.index2 = br.ReadByte();
            this.index3 = br.ReadByte();
            this.index4 = br.ReadByte();
            this.index5 = br.ReadByte();
            this.index6 = br.ReadByte();
        }

        #endregion Public Constructors

        #region Public Methods

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\n\n\nSplineData ID:  " + this.id.ToString() + " at Position: " + this.baseStreamPosition.ToString());
            sb.Append("\t" + this.value.ToString());
            //sb.Append("\t" + index1.ToString());
            //sb.Append("\t" + index2.ToString());
            sb.Append("\t" + index3.ToString());
            sb.Append("\t" + index4.ToString());
            sb.Append("\t" + index5.ToString());
            sb.Append("\t" + index6.ToString());
            return sb.ToString();
        }

        #endregion Public Methods

        #region Internal Methods

        internal void Save(BinaryWriter bw)
        {
            bw.Write(value);
            bw.Write(index3);
            bw.Write(index4);
            bw.Write(index5);
            bw.Write(index6);
        }

        #endregion Internal Methods
    }
}